//
//  SecondViewController.m
//  07-delegate和block
//
//  Created by dllo on 16/7/22.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "SecondViewController.h"
#import "FirstViewController.h"
//@class 修饰类，引入头文件中，可以避免掉，头文件的循环导入
//只声明，用到了这个类但.h 不需要引入在.m中去import
@class FirstViewController;



@interface SecondViewController ()
@property (nonatomic,copy) UITextField *textField;
@end

@implementation SecondViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(100, 100, 100, 40);
    button.backgroundColor = [UIColor greenColor];
    [button addTarget:self action:@selector(buttonClicked) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
    
    UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(100, 300, 100, 40)];
    textField.backgroundColor = [UIColor blackColor];
    textField.alpha = 0.3;
//    textField.text = self.titleString;
    textField.textColor = [UIColor whiteColor];
//    field.tintColor = [UIColor blackColor];
    [self.view addSubview:textField];
    
}


- (void)comBack
{
//    NSInteger count = self.navigationController.viewControllers.count;
//    FirstViewController *first = self.navigationController.viewControllers[count - 2];
//    first.titleTextField = _textField.text;
#warning 触发协议方法（判断delegate存不存在，判断签订delegate的类有没有实现实现协议方法）
    if (self.delegate && [self.delegate respondsToSelector:@selector(passValue:)]) {
        
    [self.delegate passValue:_textField.text];
    }
    
    [self.navigationController popToRootViewControllerAnimated:YES];
    
    
    
//    关于navigation中控制器的释放
//    navigation中viewcontroller数组，数组对对象有引用计数 + 1
//    当controller入栈时，则被加入数组，引用计数加1
//只要不出站，就不会释放
//    a-> push -> b
//    当b-》pop-》a b出站，对应释放
    
    
    
    
}

- (void)passValue:(NSString *)string
{
    
}

- (void)buttonClicked
{
    
   
    [self.navigationController popToRootViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
